//
//  PLDottedLine.m
//
//  Created by KimmanYip on 2018/1/10.
//

#import "PLDottedLine.h"

@implementation PLDottedLine

- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = [UIColor clearColor];
        self.lineColor = [UIColor blackColor];
        self.lineWidth = 1.0;
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
- (void)drawRect:(CGRect)rect
{
    CGFloat x = rect.origin.x;
    CGFloat y = rect.origin.y;
    CGFloat width = rect.size.width;
    CGFloat heigh = rect.size.height;
    CGFloat lengths[] = {4,4};
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextMoveToPoint(ctx, x, y+(heigh-self.lineWidth)/2);
    CGContextAddLineToPoint(ctx, x+width, y+(heigh-self.lineWidth)/2);
    CGContextSetLineWidth(ctx, self.lineWidth);
    CGContextSetLineDash(ctx, 0, lengths, 2);
    CGContextSetLineCap(ctx, kCGLineCapRound);
    CGContextSetLineJoin(ctx, kCGLineJoinRound);
    CGContextSetStrokeColorWithColor(ctx, self.lineColor.CGColor);
    CGContextStrokePath(ctx);
}


@end
